#include <iostream>
using namespace std;
//计算器基类
class Calculator
{
public:
    int num1;
    int num2;
    virtual int getResult(){//声明虚函数
        return 0;
    }
};
//加法类
class AddCalculator:public Calculator
{
public:
    AddCalculator(int num1,int num2){
        this->num1=num1;
        this->num2=num2;
    }
    //对基类虚函数getResult的重写
    int getResult(){
        return num1+num2;
    }
};
//乘法计算器类
class MlnCalculator:public Calculator
{
public:
    MlnCalculator(int num1,int num2){
        this->num1=num1;
        this->num2=num2;
    }
    //对基类虚函数getResult的重写
    int getResult(){
        return num1*num2;
    }
};
int fun(Calculator &p){
    return p.getResult();
}
int main()
{
    AddCalculator p1(2,3);
    MlnCalculator p2(2,3);
    cout<<fun(p1)<<endl;
    return 0;
}